import axios from 'axios'
export default {
  namespaced: true,
  state: () => ({
    token: '',
    userInfo: {
      avatar: ''
    }
  }),
  mutations: {
    updateToken (state, token) {
      state.token = token
      // 存入localStorage
      // localStorage.setItem('token', token)
    },
    updateUserInfo (state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    async  getUserInfo (context) {
      // get请求第一个参数是路径
      // 第二个参数是配置项
      // 第三个配置项里面的headers是请求头
      const { data: res } = await axios.get('/my/userinfo'
      )
      // console.log(res.data)
      context.commit('updateUserInfo', res.data)
    }
  },
  getters: {}
}
